package {
	import flash.text.StyleSheet;	
	import flash.text.TextFormat;	
	import flash.display.BitmapData;	
	import flash.display.Sprite;	
	import flash.display.Bitmap;	
	import flash.text.TextField;
	
	/**
	 * BitmapTextField add many Bitmap features to TextField, such as
	 * rotation, alpha, mask. You can use BitmapTextField as TextField,
	 * their api is the same. The only difference if BitmapTextField has
	 * a update method.
	 * @author yaowei
	 * blesswall@gmail.com
	 * 20080913
	 */
	public class BitmapTextField extends Sprite {

		public function BitmapTextField(){
			_tf = new TextField();
			_bm = new Bitmap();
			addChild(_tf);
			addChild(_bm);
			
			//we hide this textfield, don't worry the BitmapData can draw it.
			_tf.visible = false;
		}
		
		/**
		 * update mehod will draw the TextField.
		 */
		public function update():void{
			var bmd:BitmapData = new BitmapData(_tf.width+1,_tf.height+1,true,0x00FFFFFF);
			bmd.draw(_tf);
			_bm.bitmapData = bmd;
		}
		
		public function set autoUpdate(value:Boolean):void{
			_autoUpdate = value;
		}
		
		public function get autoUpdate():Boolean{
			return _autoUpdate;
		}
		
		public function set autoSize(value:String):void{
			_tf.autoSize = value;
			if(_autoUpdate)
				update();
		}
		
		public function get autoSize():String{
			return _tf.autoSize;
		}
		
		public function set background(value:Boolean):void{
			_tf.background = value;
			
			if(_autoUpdate)
				update();
		}
		
		public function get background():Boolean{
			return _tf.background;
		}
		
		public function set backgroundColor(value:uint):void{
			_tf.backgroundColor = value;
			
			if(_autoUpdate)
				update();
		}
		
		public function get backgroundColor():uint{
			return _tf.backgroundColor;
		}
		
		public function set border(value:Boolean):void{
			_tf.border = value;
			
			if(_autoUpdate)
				update();
		}
		
		public function get border():Boolean{
			return _tf.border;
		}
		
		//borderColor
		public function set borderColor(value:uint):void{
			_tf.borderColor = value;
			
			if(_autoUpdate)
				update();
		}
		
		public function get borderColor():uint{
			return _tf.borderColor;
		}
		
		//bottomScrollV [readonly]
		public function get bottomScrollV():int{
			return _tf.bottomScrollV;
		}
		
		//condenseWhite
		public function set condenseWhite(value:Boolean):void{
			_tf.condenseWhite = value;
			
			if(_autoUpdate)
				update();
		}
		
		public function get condenseWhite():Boolean{
			return _tf.condenseWhite;
		}
		
		//defaultTextFormat
		public function get defaultTextFormat():TextFormat{
			return _tf.defaultTextFormat;
		}
		
	    public function set defaultTextFormat(value:TextFormat):void {
	    	_tf.defaultTextFormat = value;
	    	
	    	if(_autoUpdate)
				update();
	    }
		
		//displayAsPassword
		public function set displayAsPassword(value:Boolean):void{
			_tf.displayAsPassword = value;
			
			if(_autoUpdate)
				update();
		}
		
		public function get displayAsPassword():Boolean{
			return _tf.displayAsPassword;
		}
		
		//embedFonts
		public function set embedFonts(value:Boolean):void{
			_tf.embedFonts = value;
			
			if(_autoUpdate)
				update();
		}
		
		public function get embedFonts():Boolean{
			return _tf.embedFonts;
		}
		
		//gridFitType
		public function set gridFitType(value:String ):void{
			_tf.gridFitType = value;
			
			if(_autoUpdate)
				update();
		}
		
		public function get gridFitType():String {
			return _tf.gridFitType;
		}
		
		//htmlText
		public function set htmlText(value:String ):void{
			_tf.htmlText = value;
			
			if(_autoUpdate)
				update();
		}
		
		public function get htmlText():String {
			return _tf.htmlText;
		}
		
		//length [read-only] 
		public function get length():int {
			return _tf.length;
		}
		
		//maxChars
		public function set maxChars(value:int ):void{
			_tf.maxChars = value;
			
			if(_autoUpdate)
				update();
		}
		
		public function get maxChars():int {
			return _tf.maxChars;
		}
		
		//maxScrollH [read-only]
		public function get maxScrollH():int{
			return _tf.maxScrollH;
		}
		
		//maxScrollV [read-only]
		public function get maxScrollV():int{
			return _tf.maxScrollV;
		}
		
		//mouseWheelEnabled
		public function set mouseWheelEnabled(value:Boolean):void{
			_tf.mouseWheelEnabled = value;
			
			if(_autoUpdate)
				update();
		}
		
		public function get mouseWheelEnabled():Boolean{
			return _tf.mouseWheelEnabled;
		}
		
		//*multiline
		public function set multiline(value:Boolean):void{
			_tf.multiline = value;
			
			if(_autoUpdate)
				update();
		}
		
		public function get multiline():Boolean{
			return _tf.multiline;
		}
		
		//numLines [read-only]
		public function get numLines():int{
			return _tf.numLines;
		}
		
		//restrict
		public function set restrict(value:String ):void{
			_tf.restrict = value;
			
			if(_autoUpdate)
				update();
		}
		
		public function get restrict():String {
			return _tf.restrict;
		}
		
		//scrollH
		public function set scrollH(value:int ):void{
			_tf.scrollH = value;
			
			if(_autoUpdate)
				update();
		}
		
		public function get scrollH():int {
			return _tf.scrollH;
		}
		
		//scrollV
		public function set scrollV(value:int ):void{
			_tf.scrollH = value;
			
			if(_autoUpdate)
				update();
		}
		
		public function get scrollV():int {
			return _tf.scrollH;
		}
		
		//selectable
		public function set selectable(value:Boolean):void{
			_tf.selectable = value;
			if(_autoUpdate)
				update();
		}
		
		public function get selectable():Boolean{
			return _tf.selectable;
		}
		
		//selectionBeginIndex [read-only]
		public function get selectionBeginIndex():int{
			return _tf.selectionBeginIndex;
		}
		
		//selectionEndIndex [read-only]
		public function get selectionEndIndex():int{
			return _tf.selectionEndIndex;
		}
		
		
		//sharpness
		public function set sharpness(value:Number):void{
			_tf.sharpness = value;
			
			if(_autoUpdate)
				update();
		}
		
		public function get sharpness():Number{
			return _tf.sharpness;
		}
		
		//styleSheet StyleSheet 
		public function set styleSheet(value:StyleSheet):void{
			_tf.styleSheet = value;
			
			if(_autoUpdate)
				update();
		}
		
		public function get styleSheet():StyleSheet{
			return _tf.styleSheet;
		}
		
		//text
		public function set text(value:String):void{
			_tf.text = value;
			
			if(_autoUpdate)
				update();
		}
		
		public function get text():String{
			return _tf.text;
		}
		
		//*textColor
		public function set textColor(value:uint):void{
			_tf.textColor = value;
			
			if(_autoUpdate)
				update();
		}
		
		public function get textColor():uint{
			return _tf.textColor;
		}
		
		//*textHeight [read-only]
		public function get textHeight():Number{
			return _tf.textHeight;
		}
		
		//*textWidth [read-only] 
		public function get textWidth():Number{
			return _tf.textWidth;
		}
		
		//thickness
		public function set thickness(value:Number):void{
			_tf.thickness = value;
			
			if(_autoUpdate)
				update();
		}
		
		public function get thickness():Number{
			return _tf.thickness;
		}
		
		//type
		public function set type(value:String):void{
			_tf.type = value;
			
			if(_autoUpdate)
				update();
		}
		
		public function get type():String{
			return _tf.type;
		}
		
		//useRichTextClipboard
		public function set useRichTextClipboard(value:Boolean):void{
			_tf.useRichTextClipboard = value;
			
			if(_autoUpdate)
				update();
		}
		
		public function get useRichTextClipboard():Boolean{
			return _tf.useRichTextClipboard;
		}
		
		//width
		public override function set width(value:Number):void{
			_tf.width = value;
			
			if(_autoUpdate)
				update();
		}
		
		public override function get width():Number{
			return _tf.width;
		}
		
		//height
		public override function set height(value:Number):void{
			_tf.height = value;
			
			if(_autoUpdate)
				update();
		}
		
		public override function get height():Number{
			return _tf.height;
		}
		
		//*wordWrap
		public function set wordWrap(value:Boolean):void{
			_tf.wordWrap = value;
			
			if(_autoUpdate)
				update();
		}
		
		public function get wordWrap():Boolean{
			return _tf.wordWrap;
		}
		
		private var _tf : TextField;
		private var _bm : Bitmap;
		private var _autoUpdate : Boolean = true;
	}
}
